package com.wy.powerbuilder.controller.hxl;
import com.github.pagehelper.PageInfo;
import com.wy.powerbuilder.entity.hxl.carcontract;
import com.wy.powerbuilder.entity.hxl.carseat;
import com.wy.powerbuilder.entity.ld.Role;
import com.wy.powerbuilder.mapper.hxl.carcontractMapper;
import com.wy.powerbuilder.service.hxl.carcontractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class carcontractController {


    @Autowired
    private carcontractMapper carconmapper;
    @Autowired
    private carcontractService carcoservice;


    //查询车位合同
    @RequestMapping(value = {"/carcontract"})
    public String selByPage(Integer pageNum, Model model,String c_userName,String c_contractid ){
        System.out.println(c_userName+"11111111111111111"+c_contractid+"1111111111113333333");
        //实现我们的分页  每页显示两条   pageInfo应该放在那里 model modelAndView map
        PageInfo<carcontract> pageInfo = carcoservice.selByPage(pageNum, 10,c_userName,c_contractid);
        model.addAttribute("pageInfo",pageInfo);
        if(c_userName==null){
            c_userName="";
        }
        if (c_contractid==null){
            c_contractid="";
        }
        model.addAttribute("c_userName",c_userName);
        model.addAttribute("c_contractid",c_contractid);
        return "carport";
    }
     //查询车位编号
    @RequestMapping("carseatsAll")
    public String carseatsAll(Model model){
        List<carseat> carseat=carcoservice.carseatsAll();
        model.addAttribute("carseat",carseat);
        return "carseatsadd";
    }
   //添加合同管理
    @ResponseBody
    @RequestMapping(value={"/addcarcontract"})
    public String addcarcontract(carcontract carse ) {
        String C_number=carse.getC_number();
        int us = carcoservice.addcarcontract(carse);
        int smbid=carcoservice.update(C_number);
        return "ok";

    }
    //销毁合同
    @RequestMapping(value={"/destroy"})
    public String destroy(String c_number,String c_state ,String c_contractid) {
        int abc = carcoservice.destroy(c_number);
        int hhh=carcoservice.compact(c_contractid);
        return "redirect:/carcontract";

    }
    //合同删除
    @RequestMapping(value = {"/deletedestroy"})
    public String delete(Integer c_id) {
        int result = carcoservice.deletedestroy(c_id);
        return "redirect:/carcontract";
    }

    //空闲车位多少条
    @RequestMapping(value = {"/selewer"})
    public String seles(Model model) {
        int result = carcoservice.sele();

        int results = carcoservice.selel();
        int selek = carcoservice.selek();
        int selem = carcoservice.selem();
        int selems = carcoservice.selems();
        int selema = carcoservice.selema();
        model.addAttribute("result",result);
        model.addAttribute("results",results);
        model.addAttribute("selek",selek);
        model.addAttribute("selem",selem);
        model.addAttribute("selems",selems);
        model.addAttribute("selema",selema);
        return "charts-7";
    }
}
